//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package javax.vpncrypto;

import java.security.Permission;
import java.security.PermissionCollection;
import java.security.spec.AlgorithmParameterSpec;
import javax.vpncrypto.spec.PBEParameterSpec;
import javax.vpncrypto.spec.RC2ParameterSpec;
import javax.vpncrypto.spec.RC5ParameterSpec;

class CryptoPermission extends Permission {
    private static final long serialVersionUID = 8987399626114087514L;
    private String alg;
    private int maxKeySize = 2147483647;
    private String exemptionMechanism = null;
    private AlgorithmParameterSpec algParamSpec = null;
    private boolean checkParam = false;
    static final String ALG_NAME_WILDCARD = "*";

    CryptoPermission(String var1) {
        super((String)null);
        this.alg = var1;
    }

    CryptoPermission(String var1, int var2) {
        super((String)null);
        this.alg = var1;
        this.maxKeySize = var2;
    }

    CryptoPermission(String var1, int var2, AlgorithmParameterSpec var3) {
        super((String)null);
        this.alg = var1;
        this.maxKeySize = var2;
        this.checkParam = true;
        this.algParamSpec = var3;
    }

    CryptoPermission(String var1, String var2) {
        super((String)null);
        this.alg = var1;
        this.exemptionMechanism = var2;
    }

    CryptoPermission(String var1, int var2, String var3) {
        super((String)null);
        this.alg = var1;
        this.exemptionMechanism = var3;
        this.maxKeySize = var2;
    }

    CryptoPermission(String var1, int var2, AlgorithmParameterSpec var3, String var4) {
        super((String)null);
        this.alg = var1;
        this.exemptionMechanism = var4;
        this.maxKeySize = var2;
        this.checkParam = true;
        this.algParamSpec = var3;
    }

    public boolean implies(Permission var1) {
        if (!(var1 instanceof CryptoPermission)) {
            return false;
        } else {
            CryptoPermission var2 = (CryptoPermission)var1;
            if (!this.alg.equalsIgnoreCase(var2.alg) && !this.alg.equalsIgnoreCase("*")) {
                return false;
            } else {
                if (var2.maxKeySize <= this.maxKeySize) {
                    if (!this.impliesParameterSpec(var2.checkParam, var2.algParamSpec)) {
                        return false;
                    }

                    if (this.impliesExemptionMechanism(var2.exemptionMechanism)) {
                        return true;
                    }
                }

                return false;
            }
        }
    }

    public boolean equals(Object var1) {
        if (var1 == this) {
            return true;
        } else if (!(var1 instanceof CryptoPermission)) {
            return false;
        } else {
            CryptoPermission var2 = (CryptoPermission)var1;
            if (this.alg.equalsIgnoreCase(var2.alg) && this.maxKeySize == var2.maxKeySize) {
                if (this.checkParam != var2.checkParam) {
                    return false;
                } else {
                    return this.equalObjects(this.exemptionMechanism, var2.exemptionMechanism) && this.equalObjects(this.algParamSpec, var2.algParamSpec);
                }
            } else {
                return false;
            }
        }
    }

    public int hashCode() {
        int var1 = this.alg.hashCode();
        var1 ^= this.maxKeySize;
        if (this.exemptionMechanism != null) {
            var1 ^= this.exemptionMechanism.hashCode();
        }

        if (this.checkParam) {
            var1 ^= 100;
        }

        if (this.algParamSpec != null) {
            var1 ^= this.algParamSpec.hashCode();
        }

        return var1;
    }

    public String getActions() {
        return null;
    }

    public PermissionCollection newPermissionCollection() {
        return new javax.vpncrypto.CryptoPermissionCollection();
    }

    final String getAlgorithm() {
        return this.alg;
    }

    final String getExemptionMechanism() {
        return this.exemptionMechanism;
    }

    final int getMaxKeySize() {
        return this.maxKeySize;
    }

    final boolean getCheckParam() {
        return this.checkParam;
    }

    final AlgorithmParameterSpec getAlgorithmParameterSpec() {
        return this.algParamSpec;
    }

    public String toString() {
        StringBuilder var1 = new StringBuilder(100);
        var1.append("(CryptoPermission " + this.alg + " " + this.maxKeySize);
        if (this.algParamSpec != null) {
            if (this.algParamSpec instanceof RC2ParameterSpec) {
                var1.append(" , effective " + ((RC2ParameterSpec)this.algParamSpec).getEffectiveKeyBits());
            } else if (this.algParamSpec instanceof RC5ParameterSpec) {
                var1.append(" , rounds " + ((RC5ParameterSpec)this.algParamSpec).getRounds());
            }
        }

        if (this.exemptionMechanism != null) {
            var1.append(" " + this.exemptionMechanism);
        }

        var1.append(")");
        return var1.toString();
    }

    private boolean impliesExemptionMechanism(String var1) {
        if (this.exemptionMechanism == null) {
            return true;
        } else if (var1 == null) {
            return false;
        } else {
            return this.exemptionMechanism.equals(var1);
        }
    }

    private boolean impliesParameterSpec(boolean var1, AlgorithmParameterSpec var2) {
        if (this.checkParam && var1) {
            if (var2 == null) {
                return true;
            } else if (this.algParamSpec == null) {
                return false;
            } else if (this.algParamSpec.getClass() != var2.getClass()) {
                return false;
            } else if (var2 instanceof RC2ParameterSpec && ((RC2ParameterSpec)var2).getEffectiveKeyBits() <= ((RC2ParameterSpec)((RC2ParameterSpec)this.algParamSpec)).getEffectiveKeyBits()) {
                return true;
            } else if (var2 instanceof RC5ParameterSpec && ((RC5ParameterSpec)var2).getRounds() <= ((RC5ParameterSpec)this.algParamSpec).getRounds()) {
                return true;
            } else if (var2 instanceof PBEParameterSpec && ((PBEParameterSpec)var2).getIterationCount() <= ((PBEParameterSpec)this.algParamSpec).getIterationCount()) {
                return true;
            } else {
                return this.algParamSpec.equals(var2);
            }
        } else {
            return !this.checkParam;
        }
    }

    private boolean equalObjects(Object var1, Object var2) {
        if (var1 == null) {
            return var2 == null;
        } else {
            return var1.equals(var2);
        }
    }
}
